
******SUPERVISOR EVALUATION OUTCOMES (TABLE C.4 TABLE C.5)********

set more off
clear all 
clear matrix
capture log close

adopath + "$main/DoFiles"																		


local seed = 999
local reps = 5000


//--> DATA: EVALUATION OUTCOMES

		use "$data/eval_fa_vars.dta", clear
	
//--> DATA: FA TREATMENT STATUS 

		sort fw_code
		merge fw_code using "$data/FWHR.dta"
		drop _m

		
		//--> REGION DUMMIES
				tab region, gen(r)
				
			

//--> OUTPUT: TABLE C.4 (SUBJECTIVE EVALAUTION OUTCOMES)	
	*********************************************************************************************************************************************************
	
		local credit_var eval_disbursement eval_recovery 
		local social_var eval_COmeet eval_COsave
		
	

	
		//--> REGRESSION OUTPUT (FOR ESTIMATED COEEFICIENTS ONLY)
			****************************************		
	
			reg eval_cro r1 r2 r3 treat_credit treat_sm
			sum eval_cro if treat==0
			local m = r(mean)
			outreg2 using "$output/tableC_4 (coeff).xls", replace addstat("CONTROL MEAN", `m')  noaster stats(coef) keep(treat_credit treat_sm) nocons nor2
			local replace
			foreach v in `credit_var'{
				reg `v' r1 r2 r3 treat_credit treat_sm if eval_cro==1
				sum `v' if treat==0 & eval_cro==1
				local m = r(mean)
				outreg2 using "$output/tableC_4 (coeff).xls", `replace' addstat("CONTROL MEAN", `m') noaster stats(coef) keep(treat_credit treat_sm) nocons nor2
				local replace
				}
			
			reg eval_so r1 r2 r3 treat_credit treat_sm
			sum eval_so if treat==0
			local m = r(mean)
			outreg2 using "$output/tableC_4 (coeff).xls", `replace' addstat("CONTROL MEAN", `m') noaster stats(coef) keep(treat_credit treat_sm) nocons nor2
			local replace
			foreach v in `social_var'{
				reg `v' r1 r2 r3 treat_credit treat_sm if eval_so==1
				sum `v' if treat==0 & eval_so==1
				local m = r(mean)
				outreg2 using "$output/tableC_4 (coeff).xls", `replace' addstat("CONTROL MEAN", `m') noaster stats(coef) keep(treat_credit treat_sm) nocons nor2
				local replace
				}	
				
				
				
		log using "$output/tableC_4 (p-values)", replace	
		
		//--> CALCULATE WILDCLUSTER T-BOOTSTRAP P VALUES
			****************************************		
			
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL
				
					cgmwildboot eval_cro r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')
					foreach v in `credit_var' {
						cgmwildboot `v' r1 r2 r3 treat_credit treat_sm if eval_cro==1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')
						}
					
					cgmwildboot eval_so r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')
					foreach v in `social_var' {
						cgmwildboot `v' r1 r2 r3 treat_credit treat_sm if eval_so==1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')
						}
					
			//--> CREDIT VS. SOCIAL
			
					g x1 = treat_credit + treat_sm
					g test1 = treat_credit //RELEVANT VAR FOR F TEST
						
					cgmwildboot eval_cro r1 r2 r3 x1 test1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')
					foreach v in `credit_var' {
						cgmwildboot `v' r1 r2 r3 x1 test1 if eval_cro==1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')
						}
					
					cgmwildboot eval_so r1 r2 r3 x1 test1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')
					foreach v in `social_var' {
						cgmwildboot `v' r1 r2 r3 x1 test1 if eval_so==1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')
						}
					

		//--> CALCULATE RANDOMIZATION INFERENCE BASED P VALUES
			****************************************						
						
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL				
					
					randcmd((treat_credit treat_sm) reg eval_cro treat_credit treat_sm r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
					foreach v in `credit_var' {
						randcmd((treat_credit treat_sm) reg `v' treat_credit treat_sm r1 r2 r3 if eval_cro==1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
						}
						
					randcmd((treat_credit treat_sm) reg eval_so treat_credit treat_sm r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
					foreach v in `social_var' {
						randcmd((treat_credit treat_sm) reg `v' treat_credit treat_sm r1 r2 r3 if eval_so==1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
						}	
							
			//--> CREDIT VS. SOCIAL (F TEST)
					
					randcmd((treat_credit) reg eval_cro treat_credit x1 r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
					foreach v in `credit_var' {
						randcmd((treat_credit) reg `v' treat_credit x1 r1 r2 r3 if eval_cro==1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
						}

					randcmd((treat_credit) reg eval_so treat_credit x1 r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
					foreach v in `social_var' {
						randcmd((treat_credit) reg `v' treat_credit x1 r1 r2 r3 if eval_so==1, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
						}
						
						
	log close
	*********************************************************************************************************************************************************
	
	
	drop x1 test1
	
	

//--> OUTPUT: TABLE C.5 (SUPERVISOR EFFORT)	
	*********************************************************************************************************************************************************
	
		local credit_var diff_recovery_rate diff_num_active_loan 
		local social_var diff_attendance

	
		//--> REGRESSION OUTPUT (FOR ESTIMATED COEEFICIENTS ONLY)
			****************************************		
	
			
			local replace replace
			foreach v in `credit_var' `social_var'{
				reg `v' r1 r2 r3 treat_credit treat_sm
				sum `v' if treat==0
				local m = r(mean)
				outreg2 using "$output/tableC_5 (coeff).xls", `replace' addstat("CONTROL MEAN", `m') noaster stats(coef) keep(treat_credit treat_sm) nocons nor2
				local replace
				}	
	
		log using "$output/tableC_5 (p-values)", replace	
		
	
		
		//--> CALCULATE WILDCLUSTER T-BOOTSTRAP P VALUES
			****************************************		
			
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL
				
					foreach v in `credit_var' `social_var'{
						cgmwildboot `v' r1 r2 r3 treat_credit treat_sm, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')
						}
						
			//--> CREDIT VS. SOCIAL
				
						g x1 = treat_credit + treat_sm
						g test1 = treat_credit //RELEVANT VAR FOR F TEST
							
						foreach v in `credit_var' `social_var' {
							cgmwildboot `v' r1 r2 r3 test1 x1, cluster(fu_feb05) bootcluster(fu_feb05) seed(`seed')
							}			
							
		//--> CALCULATE RANDOMIZATION INFERENCE BASED P VALUES
			****************************************						
						
			//--> CREDIT VS. CONTROL; SOCIAL VS. CONTROL				
					
					foreach v in `credit_var' `social_var' {
						randcmd((treat_credit treat_sm) reg `v' treat_credit treat_sm r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed')	
						}
								
			//--> CREDIT VS. SOCIAL (F TEST)
					
					foreach v in `credit_var' `social_var' {
						randcmd((treat_credit) reg `v' treat_credit x1 r1 r2 r3, cluster(fu_feb05)), treatvars(treat_credit treat_sm) groupvar(fu_feb05)reps(`reps') seed(`seed') calc1(replace x1 = treat_credit + treat_sm)
						}					
								
	log close
	*********************************************************************************************************************************************************
									
